<?php
if (session_id() == '') {
    session_start();
}
//session_start();
require_once('UserDetails.php');
$objUser = new UserDetails();
if(isset($_SESSION['userdetail']) && !empty($_SESSION['userdetail'])) {
$objUser = unserialize($_SESSION['userdetail']);
}
?>
<script type="text/javascript" language="javascript" >

function changeLabel(arg)
{
	if(arg.id=="mstore")
	{
	$('label[for=FullName]').text('Medical Store Name');
	$('label[for=Address]').text('Store Address');
	} else if(arg.id=="iuser")
	{
	$('label[for=FullName]').text('Full Name');
	$('label[for=Address]').text('Address');
	}
}
function validateForm(args)
{
	if($('#'+args.id).val()=='')
	{
		$('#sp'+args.id).css("visibility", "visible");
		args.focus();
		return false;
	} else
	{
	$('#sp'+args.id).css("visibility", "hidden");
	}
		
}
function MatchPassowrd(args)
{
 var pass1 = $('#Password').val();
 var pass2 = $('#ConfirmPassword').val();
 if((pass1!="" && pass2!="" ) && pass1!=pass2)
 {
 $('#spConfirmPassword1').css("display", "block");
	//args.focus();
	return false;
 } else
 {
 $('#spConfirmPassword1').css("display", "none");
 }
}
</script>
<?php
if (!empty($_POST))
{
$isValid=1;
$errMessage="<br/><div class='text-danger' style='font-weight:bold'><ul>";
	$objUser1 = new UserDetails();
	//$objUser->UserId=$_POST[''];
	/* if(isset($_POST['UserName']) && !empty($_POST['UserName'])){
		$objUser1->UserName=$_POST['UserName'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>User Name is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['Password']) && !empty($_POST['Password'])){
		$objUser1->Password=$_POST['Password'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>Password is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['FullName']) && !empty($_POST['FullName'])){
		$objUser1->FullName=$_POST['FullName'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>Full Name is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['EmailAddress']) && !empty($_POST['EmailAddress'])){
		$objUser1->EmailAddress=$_POST['EmailAddress'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>Email Address is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['Address']) && !empty($_POST['Address'])){
		$objUser1->Address=$_POST['Address'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>Address is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['City']) && !empty($_POST['City'])){
		$objUser1->City=$_POST['City'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>City is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['State']) && !empty($_POST['State'])){
		$objUser1->State=$_POST['State'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>State is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['MobileNumber']) && !empty($_POST['MobileNumber'])){
		$objUser1->Mobile=$_POST['MobileNumber'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>Mobile Number is Required</li>";
		$isValid=0;
	}
	if($isValid==1 && isset($_POST['userType']) && !empty($_POST['userType'])){
		$objUser1->UserType=$_POST['userType'];
		$isValid=1;
	} else{
		$errMessage=$errMessage."<li>Type is Required</li>";
		$isValid=0;
	}
	*/
	//$objUser->Country=$_POST[''];
	//$objUser->PinCode=$_POST[''];
	//echo 'Is valid is '.$isValid;
	
	//$objUser->Longitude;
	//$objUser->Latitude;
	if(!isset($_POST['UserName']) || empty($_POST['UserName'])){
		$errMessage=$errMessage."<li>User Name is Required</li>";
		$isValid=0;
	} 
	if(!isset($_POST['Password']) || empty($_POST['Password'])){
		$errMessage=$errMessage."<li>Password is Required</li>";
		$isValid=0;
	} 
	if(!isset($_POST['FullName']) || empty($_POST['FullName'])){
		$errMessage=$errMessage."<li>Full Name is Required</li>";
		$isValid=0;
	} 
	if(!isset($_POST['EmailAddress']) || empty($_POST['EmailAddress'])){
		$errMessage=$errMessage."<li>Email Address is Required</li>";
		$isValid=0;
	} 
	if(!isset($_POST['Address']) || empty($_POST['Address'])){
		$errMessage=$errMessage."<li>Address is Required</li>";
		$isValid=0;
	}
	if(!isset($_POST['City']) ||empty($_POST['City'])){
		$errMessage=$errMessage."<li>City is Required</li>";
		$isValid=0;
	}
	if(!isset($_POST['State']) ||empty($_POST['State'])){
		$errMessage=$errMessage."<li>State is Required</li>";
		$isValid=0;
	}
	if(!isset($_POST['MobileNumber']) ||empty($_POST['MobileNumber'])){
		$errMessage=$errMessage."<li>Mobile Number is Required</li>";
		$isValid=0;
	}
	if(!isset($_POST['userType']) ||empty($_POST['userType'])){
		$errMessage=$errMessage."<li>Type is Required</li>";
		$isValid=0;
	} 
	$errMessage = $errMessage."</ul></div>";
	if($isValid==1){
	$objUser1->UserName=$_POST['UserName'];	
	$objUser1->Password=$_POST['Password'];
	$objUser1->FullName=$_POST['FullName'];
	$objUser1->EmailAddress=$_POST['EmailAddress'];
	$objUser1->Address=$_POST['Address'];
	$objUser1->City=$_POST['City'];
	$objUser1->State=$_POST['State'];
	$objUser1->Mobile=$_POST['MobileNumber'];
	$objUser1->UserType=$_POST['userType'];
	$objUser1->RegisterUser();
	$URL="index.php?Login";
	echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">'; 
	} else{
	echo $errMessage;
	}
	
}
?>
<h2>Register.</h2>
    <div class="form-horizontal">
        <h4>Create a new account.</h4>
        <hr />
        <div id="ctl00" class="text-danger" style="display:none;">

</div>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
		<div class="form-group">
            <label for="userType" class="col-md-2 control-label">Register as </label>
            <div class="col-md-10">
               <input name="userType" type="radio" id="mstore" value="mstore" onclick="javascript:changeLabel(this);"/>
			   <label for="mstore">Medical Store</label>  &nbsp;&nbsp;
			   <input name="userType" checked="checked" type="radio" id="iuser" value="iuser" onclick="javascript:changeLabel(this);"/> 
			   <label for="iuser">Normal User</label>
            </div>
        </div>
        <div class="form-group">
            <label for="FullName" class="col-md-2 control-label">Full Name</label>
            <div class="col-md-10">
                <input name="FullName" type="text" id="FullName" class="form-control" onblur="javascript:return validateForm(this);" />
                <span id="spFullName" class="text-danger" style="visibility:hidden;">Full Name field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="Address" class="col-md-2 control-label">Address</label>
            <div class="col-md-10">
                <textarea name="Address" rows="2" cols="20" id="Address" class="form-control" onblur="javascript:return validateForm(this);">
</textarea>
                <span id="spAddress" class="text-danger" style="visibility:hidden;">Address field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="City" class="col-md-2 control-label">City</label>
            <div class="col-md-10">
                <select name="City" id="City" class="form-control" onblur="javascript:return validateForm(this);">
	<option value="Noida">Noida</option>

</select>
                <span id="spCity" class="text-danger" style="visibility:hidden;">City field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="State" class="col-md-2 control-label">State</label>
            <div class="col-md-10">
                <select name="State" id="State" class="form-control" onblur="javascript:return validateForm(this);">
				<option value="UP">Uttar Pradesh</option>
				</select>
                <span id="spState" class="text-danger" style="visibility:hidden;">State field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="EmailAddress" class="col-md-2 control-label">Email Address</label>
            <div class="col-md-10">
                <input name="EmailAddress" type="email" id="EmailAddress" class="form-control" onblur="javascript:return validateForm(this);" />
                <span id="spEmailAddress" class="text-danger" style="visibility:hidden;">Email Address field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="MobileNumber" class="col-md-2 control-label">Mobile Number</label>
            <div class="col-md-10">
                <input name="MobileNumber" type="text" id="MobileNumber" class="form-control" onblur="javascript:return validateForm(this);" />
                <span id="spMobileNumber" class="text-danger" style="visibility:hidden;">Mobile Number field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="UserName" class="col-md-2 control-label">User name</label>
            <div class="col-md-10">
                <input name="UserName" type="text" id="UserName" class="form-control" value="<?php echo $objUser->UserName; ?>" onblur="javascript:return validateForm(this);"/>
                <span id="spUserName" class="text-danger" style="visibility:hidden;">The user name field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="Password" class="col-md-2 control-label">Password</label>
            <div class="col-md-10">
                <input name="Password" type="password" id="Password" class="form-control" onblur="javascript:validateForm(this);MatchPassowrd(this);"/>
                <span id="spPassword" class="text-danger" style="visibility:hidden;">The password field is required.</span>
            </div>
        </div>
        <div class="form-group">
            <label for="ConfirmPassword" class="col-md-2 control-label">Confirm password</label>
            <div class="col-md-10">
                <input name="ConfirmPassword" type="password" id="ConfirmPassword" class="form-control" onblur="javascript:validateForm(this);MatchPassowrd(this);" />
                <span id="spConfirmPassword" class="text-danger" style="visibility:hidden;">The confirm password field is required.</span>
                <span id="spConfirmPassword1" class="text-danger" style="display:none;">The password and confirmation password do not match.</span>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" name="btnRegister" value="Register" id="btnRegister" class="btn btn-primary btn-large" />
				<input type="reset" name="btnReset" value="Clear" id="btnReset" class="btn btn-primary btn-large" />
            </div>
        </div>
</form>